package com.hospital.demo.controller.dingyuxin;

import com.hospital.demo.enums.UserType;
import com.hospital.demo.model.dingyuxin.Payment;
import com.hospital.demo.model.dingyuxin.Paymentdetail;
import com.hospital.demo.service.dingyuxin.UserPaymentSer;
import com.hospital.demo.service.jiashuai.LoginSer;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dyx_people")
@Api(tags={"DYX_患者接口"})
public class PeopleCon {

    @Autowired
    private UserPaymentSer userPaymentSer;

    @Autowired
    private LoginSer loginSer;

    @ApiOperation(value = "缴费处生成订单和订单详情", notes = "")
    @PostMapping(value = "/addFinance")
    private ResultVO addFinance(int peopleaccent, String druginformation,String totalpay) {
        Payment payment = new Payment();
        payment.setTotalpay(Double.valueOf(totalpay));
        payment.setPeopleaccent(peopleaccent);
        Paymentdetail paymentdetail = new Paymentdetail();
        paymentdetail.setDrugid(druginformation);
        return ResultUtils.success(userPaymentSer.buyDrugs(payment,paymentdetail));
    }

    @ApiOperation(value = "患者退货", notes = "")
    @GetMapping(value = "/fundBack")
    private ResultVO fundBack(int paymentid) {
        return ResultUtils.success(userPaymentSer.fundBack(paymentid));
    }

    @ApiOperation(value = "显示历史账单", notes = "")
    @GetMapping(value = "/paymentList")
    private ResultVO paymentList(String token) {
        int peopleaccount = Integer.valueOf(loginSer.check(token, UserType.INSURANCE_PEOPLE.getCode()));
        return ResultUtils.success(userPaymentSer.paymentList(peopleaccount));
    }

    @ApiOperation(value = "显示医保余额", notes = "")
    @GetMapping(value = "/balance")
    private ResultVO balance(String token) {
        int peopleaccount = Integer.valueOf(loginSer.check(token, UserType.INSURANCE_PEOPLE.getCode()));
        return ResultUtils.success(userPaymentSer.balance(peopleaccount));
    }
}
